<?php


namespace app\api\controller;


use app\common\controller\Api;
use app\common\model\Servicetype;
use app\common\model\Service as ServiceModel;

/**
 * 服务接口
 * Class Service
 * @package app\api\controller
 */
class Service extends Api
{
    protected $noNeedRight = '*';
    protected $noNeedLogin = '*';

    /**
     * 服务分类
     *
     * @ApiMethod (POST)
     */
    public function type()
    {
        $serviceTypeModel = new Servicetype();
        $fields = ['id', 'name', 'title'];
        $data = $serviceTypeModel->where('status', 1)->field($fields)->order('weigh', 'desc')->select();
        $this->success(__('Operation completed'), $data);
    }

    /**
     * 服务列表
     *
     * @ApiMethod (POST)
     * @ApiParams (name="page", type="string", required=false, description="分页页码, 默认1")
     * @ApiParams (name="limit", type="string", required=false, description="分页, 每页数据条数, 默认10")
     * @ApiParams (name="type", type="string", required=true, description="分类")
     */
    public function list()
    {
        $page = $this->request->post('page', 1);
        $limit = $this->request->post('limit', 10);
        $type = $this->request->post('type', '');
        $serviceModel = new ServiceModel();
        if (!empty($type)) {
            $serviceModel = $serviceModel->where('type_id', $type);
        }
        $data = $serviceModel->page($page, $limit)->order('weigh', 'desc')->select();
        $this->success(__('Operation completed'), $data);
    }
}